home *** CD-ROM | disk | FTP | other *** search
- /**
- * Scout - The Amiga System Monitor
- *
- *------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * You must not use this source code to gain profit of any kind!
- *
- *------------------------------------------------------------------
- *
- * @author Andreas Gelhausen
- * @author Richard Körber <rkoerber@gmx.de>
- */
-
-
-
- #include "scout_assigns.h"
-
- extern struct ExecBase *SysBase;
- extern struct DosLibrary *DOSBase;
-
- int asscnt;
-
- #define AssPuddleSize 1024
- #define AssThreshSize 512
-
- APTR AssPool = NULL;
-
- __asm LONG asslist_dspfunc(register __a2 char **array, register __a1 struct AssEntry *assentry, register __a0 struct Hook *hook) {
- if (assentry) {
- *array++ = assentry->ass_address;
- *array++ = assentry->ass_name;
- *array++ = assentry->ass_path;
- *array = NULL;
- } else {
- *array++ = ESC "bAddress";
- *array++ = ESC "bName";
- *array++ = ESC "bPath";
- *array++ = NULL;
- }
- return(0);
- }
-
- struct Hook asslist_dsphook = {
- {NULL, NULL},
- (ULONG (* )())asslist_dspfunc,
- NULL, NULL
- };
-
- void FreeAssigns (void) {
- if (AssPool) {
- if (AP_Scout) {
- set (asstext,MUIA_Text_Contents,"");
- DoMethod (asslist,MUIM_List_Clear);
- }
- AsmDeletePool (AssPool,SysBase);
- AssPool = NULL;
- }
- }
-
- int GetAssigns (struct AssEntry **first) {
- struct AssEntry *assentry,*previous = NULL;
- struct DosList *dev;
- struct AssignList *list;
- struct FileInfoBlock *infoBlock;
-
- int asscnt = 0;
- *first = 0;
-
- if (! AssPool)
- AssPool = AsmCreatePool (MEMF_ANY|MEMF_CLEAR,AssPuddleSize,AssThreshSize,SysBase);
-
- dev = DOSLIST;
-
- if (clientstate) {
- char tmpbuffer[256];
-
- if (SendDaemon ("GetAssList")) {
- while ((assentry = AsmAllocPooled (AssPool,sizeof (struct AssEntry),SysBase)) \
- && (ReceiveDecodedEntry ((UBYTE *) assentry, sizeof (struct AssEntry) - 4)) \
- && (sgets (client_socket, tmpbuffer, 256))) {
-
- if (assentry->ass_path = AsmAllocPooled (AssPool, strlen (tmpbuffer) + 1, SysBase)) {
- strncpy (assentry->ass_path, tmpbuffer, strlen (tmpbuffer) + 1);
- }
-
- IsHex (assentry->ass_address, (long *) &assentry->ass_adr);
-
- if (! *first)
- *first = assentry;
- if (previous)
- previous->ass_next = assentry;
-
- asscnt++;
- previous = assentry;
- }
- }
- } else {
- if (infoBlock = AllocMem (sizeof (struct FileInfoBlock), MEMF_ANY|MEMF_CLEAR)) {
- while ((dev != 0) && (assentry = AsmAllocPooled (AssPool,sizeof (struct AssEntry),SysBase))) {
- if ((dev->dol_Type == DLT_DIRECTORY) || (dev->dol_Type == DLT_LATE) || (dev->dol_Type == DLT_NONBINDING)) {
- if (! *first)
- *first = assentry;
- if (previous)
- previous->ass_next = assentry;
-
- assentry->ass_adr = (char *) dev;
- sprintf (assentry->ass_address, "$%08x", dev);
- strncpy (assentry->ass_name, (char const *) ((dev->dol_Name)<<2)+1, 20);
-
- if (Examine (dev->dol_Lock, infoBlock)) {
- tmpstr[0] = '\0';
- NameFromLock (dev->dol_Lock, tmpstr, PATHLENGTH);
-
- if ((dev->dol_Type == DLT_DIRECTORY) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (tmpstr) + 1,SysBase))) {
- strcpy (assentry->ass_path, tmpstr);
- } else if ((dev->dol_Type == DLT_LATE) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3,SysBase))) {
- sprintf (assentry->ass_path, "<%s>", dev->dol_misc.dol_assign.dol_AssignName);
- } else if ((dev->dol_Type == DLT_NONBINDING) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3,SysBase))) {
- sprintf (assentry->ass_path, "[%s]", dev->dol_misc.dol_assign.dol_AssignName);
- }
- }
- asscnt++;
-
- previous = assentry;
- list = dev->dol_misc.dol_assign.dol_List;
-
- while ((list) && (assentry = AsmAllocPooled (AssPool,sizeof (struct AssEntry),SysBase))) {
- if (previous)
- previous->ass_next = assentry;
-
- assentry->ass_adr = (char *) (list->al_Lock);
- sprintf (assentry->ass_address, "$%08x", (char *) (list->al_Lock<<2));
- strcpy (assentry->ass_name, (char const *) ((dev->dol_Name)<<2)+1);
-
- if (Examine (list->al_Lock, infoBlock)) {
- tmpstr[0] = '\0';
- NameFromLock (list->al_Lock, tmpstr, PATHLENGTH);
-
- if ((dev->dol_Type == DLT_DIRECTORY) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (tmpstr) + 7,SysBase))) {
- sprintf (assentry->ass_path, " + %s", tmpstr);
- }
- }
- asscnt++;
-
- previous = assentry;
- list = (struct AssignList *) (list->al_Next);
- }
- }
- dev = (struct DosList *)((dev->dol_Next)<<2);
- }
- FreeMem (infoBlock, sizeof (struct FileInfoBlock));
- // infoBlock = NULL;
- }
- }
- return (asscnt);
- }
-
- void PrintAssigns (char *filename) {
- int i=1;
- BPTR handle;
- struct AssEntry *entryp;
-
- handle = HandlePrintStart (filename);
- if ((handle) && (PrintOneLine (handle, "\n Address Name Path\n\n"))) {
- if (! WI_Assigns) {
- i = GetAssigns (&entryp);
- }
- if (i) {
- for (i=0;;i++) {
- if (WI_Assigns)
- DoMethod (asslist,MUIM_List_GetEntry,i,&entryp);
- if (!entryp) break;
-
- sprintf (tmpstr2, " %9ls %-10ls %ls\n", entryp->ass_address, entryp->ass_name, entryp->ass_path);
- if (! (PrintOneLine (handle, tmpstr2)))
- break;
-
- if (! WI_Assigns)
- entryp = entryp->ass_next;
- }
- }
- }
- HandlePrintStop();
- }
-
- void ShowAssigns (void) {
- struct AssEntry *ass;
-
- ApplicationSleep();
- set (asslist,MUIA_List_Quiet,TRUE);
- set (asslist,MUIA_List_CompareHook,asslist_cmphook_ptr);
- set (BT_AssRemove, MUIA_Disabled, TRUE);
-
- FreeAssigns();
- asscnt = GetAssigns (&ass);
-
- while (ass) {
- InsertSortedEntry (asslist, (APTR *) &ass);
- ass = ass->ass_next;
- }
-
- SetCountText (asscount, asscnt);
- AwakeApplication();
- set (asslist,MUIA_List_Quiet,FALSE);
- }
-
- void SendAssList (void) {
- struct AssEntry *ass;
-
- FreeAssigns();
- asscnt = GetAssigns (&ass);
-
- while (ass) {
- SendEncodedEntry ((UBYTE *) ass, sizeof (struct AssEntry) - 4);
- SendClient ((UBYTE *) ass->ass_path);
- ass = ass->ass_next;
- }
- FreeAssigns();
- }
-
-